package org.oschina.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.oschina.api.BaseController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * 处理BaseController里的request和rseponse对象
 */
public class BaseControllerHandleInterceptor extends HandlerInterceptorAdapter  {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object handler) throws Exception
	{
		HandlerMethod handlerMethod=(HandlerMethod)handler;
		if(handlerMethod.getBean() instanceof BaseController)
		{
			BaseController baseController=(BaseController)handlerMethod.getBean();
			baseController.setRequest(request);
			baseController.setResponse(response);
		}
		return true;
	}
}